interface PayloadMap {
    [key: string]: any;
}
export type ActionMap<P> = {
    [K in keyof P]: (payload?: P[K]) => any;
};
function actionBuilder<P extends PayloadMap>(model: any): ActionMap<P> {
    const { reducers = {}, effects = {}, namespace } = model;
    const reducerKeys = Object.keys(reducers);
    const effectKeys = Object.keys(effects);

    const actionMap = [...reducerKeys, ...effectKeys].reduce<any>((map, key) => {
        const type = `${namespace}/${key}`;

        const actionFn = function (payload?: any) {
            return { type, payload };
        };

        actionFn.type = type;

        map[key] = actionFn;

        return map;
    }, {});

    return actionMap;
}
// action 结构为 {type:`${namespace}/${key}`,payload}
// dispatch(action(payload))  # 只有一个参数
// 相当于直接 dispatch({type:`${namespace}/${key}`,payload})
//
export default actionBuilder;
